
_init:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:

char *argv[] = { "sh", 0 };

int
main(void)
{
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	83 e4 f0             	and    $0xfffffff0,%esp
   6:	83 ec 20             	sub    $0x20,%esp
  int pid, wpid;

  if(open("console", O_RDWR) < 0){
   9:	c7 44 24 04 02 00 00 	movl   $0x2,0x4(%esp)
  10:	00 
  11:	c7 04 24 6d 0f 00 00 	movl   $0xf6d,(%esp)
  18:	e8 9f 03 00 00       	call   3bc <open>
  1d:	85 c0                	test   %eax,%eax
  1f:	79 30                	jns    51 <main+0x51>
    mknod("console", 1, 1);
  21:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
  28:	00 
  29:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  30:	00 
  31:	c7 04 24 6d 0f 00 00 	movl   $0xf6d,(%esp)
  38:	e8 87 03 00 00       	call   3c4 <mknod>
    open("console", O_RDWR);
  3d:	c7 44 24 04 02 00 00 	movl   $0x2,0x4(%esp)
  44:	00 
  45:	c7 04 24 6d 0f 00 00 	movl   $0xf6d,(%esp)
  4c:	e8 6b 03 00 00       	call   3bc <open>
  }
  dup(0);  // stdout
  51:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  58:	e8 97 03 00 00       	call   3f4 <dup>
  dup(0);  // stderr
  5d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  64:	e8 8b 03 00 00       	call   3f4 <dup>
  69:	eb 01                	jmp    6c <main+0x6c>
      printf(1, "init: exec sh failed\n");
      exit();
    }
    while((wpid=wait()) >= 0 && wpid != pid)
      printf(1, "zombie!\n");
  }
  6b:	90                   	nop
  }
  dup(0);  // stdout
  dup(0);  // stderr

  for(;;){
    printf(1, "init: starting sh\n");
  6c:	c7 44 24 04 75 0f 00 	movl   $0xf75,0x4(%esp)
  73:	00 
  74:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
  7b:	e8 99 04 00 00       	call   519 <printf>
    pid = fork();
  80:	e8 ef 02 00 00       	call   374 <fork>
  85:	89 44 24 1c          	mov    %eax,0x1c(%esp)
    if(pid < 0){
  89:	83 7c 24 1c 00       	cmpl   $0x0,0x1c(%esp)
  8e:	79 19                	jns    a9 <main+0xa9>
      printf(1, "init: fork failed\n");
  90:	c7 44 24 04 88 0f 00 	movl   $0xf88,0x4(%esp)
  97:	00 
  98:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
  9f:	e8 75 04 00 00       	call   519 <printf>
      exit();
  a4:	e8 d3 02 00 00       	call   37c <exit>
    }
    if(pid == 0){
  a9:	83 7c 24 1c 00       	cmpl   $0x0,0x1c(%esp)
  ae:	75 41                	jne    f1 <main+0xf1>
      exec("sh", argv);
  b0:	c7 44 24 04 18 14 00 	movl   $0x1418,0x4(%esp)
  b7:	00 
  b8:	c7 04 24 6a 0f 00 00 	movl   $0xf6a,(%esp)
  bf:	e8 f0 02 00 00       	call   3b4 <exec>
      printf(1, "init: exec sh failed\n");
  c4:	c7 44 24 04 9b 0f 00 	movl   $0xf9b,0x4(%esp)
  cb:	00 
  cc:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
  d3:	e8 41 04 00 00       	call   519 <printf>
      exit();
  d8:	e8 9f 02 00 00       	call   37c <exit>
    }
    while((wpid=wait()) >= 0 && wpid != pid)
      printf(1, "zombie!\n");
  dd:	c7 44 24 04 b1 0f 00 	movl   $0xfb1,0x4(%esp)
  e4:	00 
  e5:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
  ec:	e8 28 04 00 00       	call   519 <printf>
    if(pid == 0){
      exec("sh", argv);
      printf(1, "init: exec sh failed\n");
      exit();
    }
    while((wpid=wait()) >= 0 && wpid != pid)
  f1:	e8 8e 02 00 00       	call   384 <wait>
  f6:	89 44 24 18          	mov    %eax,0x18(%esp)
  fa:	83 7c 24 18 00       	cmpl   $0x0,0x18(%esp)
  ff:	0f 88 66 ff ff ff    	js     6b <main+0x6b>
 105:	8b 44 24 18          	mov    0x18(%esp),%eax
 109:	3b 44 24 1c          	cmp    0x1c(%esp),%eax
 10d:	75 ce                	jne    dd <main+0xdd>
      printf(1, "zombie!\n");
  }
 10f:	e9 57 ff ff ff       	jmp    6b <main+0x6b>

00000114 <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
 114:	55                   	push   %ebp
 115:	89 e5                	mov    %esp,%ebp
 117:	57                   	push   %edi
 118:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
 119:	8b 4d 08             	mov    0x8(%ebp),%ecx
 11c:	8b 55 10             	mov    0x10(%ebp),%edx
 11f:	8b 45 0c             	mov    0xc(%ebp),%eax
 122:	89 cb                	mov    %ecx,%ebx
 124:	89 df                	mov    %ebx,%edi
 126:	89 d1                	mov    %edx,%ecx
 128:	fc                   	cld    
 129:	f3 aa                	rep stos %al,%es:(%edi)
 12b:	89 ca                	mov    %ecx,%edx
 12d:	89 fb                	mov    %edi,%ebx
 12f:	89 5d 08             	mov    %ebx,0x8(%ebp)
 132:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
 135:	5b                   	pop    %ebx
 136:	5f                   	pop    %edi
 137:	5d                   	pop    %ebp
 138:	c3                   	ret    

00000139 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
 139:	55                   	push   %ebp
 13a:	89 e5                	mov    %esp,%ebp
 13c:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
 13f:	8b 45 08             	mov    0x8(%ebp),%eax
 142:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
 145:	90                   	nop
 146:	8b 45 0c             	mov    0xc(%ebp),%eax
 149:	0f b6 10             	movzbl (%eax),%edx
 14c:	8b 45 08             	mov    0x8(%ebp),%eax
 14f:	88 10                	mov    %dl,(%eax)
 151:	8b 45 08             	mov    0x8(%ebp),%eax
 154:	0f b6 00             	movzbl (%eax),%eax
 157:	84 c0                	test   %al,%al
 159:	0f 95 c0             	setne  %al
 15c:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 160:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
 164:	84 c0                	test   %al,%al
 166:	75 de                	jne    146 <strcpy+0xd>
    ;
  return os;
 168:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 16b:	c9                   	leave  
 16c:	c3                   	ret    

0000016d <strcmp>:

int
strcmp(const char *p, const char *q)
{
 16d:	55                   	push   %ebp
 16e:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
 170:	eb 08                	jmp    17a <strcmp+0xd>
    p++, q++;
 172:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 176:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
 17a:	8b 45 08             	mov    0x8(%ebp),%eax
 17d:	0f b6 00             	movzbl (%eax),%eax
 180:	84 c0                	test   %al,%al
 182:	74 10                	je     194 <strcmp+0x27>
 184:	8b 45 08             	mov    0x8(%ebp),%eax
 187:	0f b6 10             	movzbl (%eax),%edx
 18a:	8b 45 0c             	mov    0xc(%ebp),%eax
 18d:	0f b6 00             	movzbl (%eax),%eax
 190:	38 c2                	cmp    %al,%dl
 192:	74 de                	je     172 <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
 194:	8b 45 08             	mov    0x8(%ebp),%eax
 197:	0f b6 00             	movzbl (%eax),%eax
 19a:	0f b6 d0             	movzbl %al,%edx
 19d:	8b 45 0c             	mov    0xc(%ebp),%eax
 1a0:	0f b6 00             	movzbl (%eax),%eax
 1a3:	0f b6 c0             	movzbl %al,%eax
 1a6:	89 d1                	mov    %edx,%ecx
 1a8:	29 c1                	sub    %eax,%ecx
 1aa:	89 c8                	mov    %ecx,%eax
}
 1ac:	5d                   	pop    %ebp
 1ad:	c3                   	ret    

000001ae <strlen>:

uint
strlen(char *s)
{
 1ae:	55                   	push   %ebp
 1af:	89 e5                	mov    %esp,%ebp
 1b1:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
 1b4:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 1bb:	eb 04                	jmp    1c1 <strlen+0x13>
 1bd:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 1c1:	8b 55 fc             	mov    -0x4(%ebp),%edx
 1c4:	8b 45 08             	mov    0x8(%ebp),%eax
 1c7:	01 d0                	add    %edx,%eax
 1c9:	0f b6 00             	movzbl (%eax),%eax
 1cc:	84 c0                	test   %al,%al
 1ce:	75 ed                	jne    1bd <strlen+0xf>
    ;
  return n;
 1d0:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 1d3:	c9                   	leave  
 1d4:	c3                   	ret    

000001d5 <memset>:

void*
memset(void *dst, int c, uint n)
{
 1d5:	55                   	push   %ebp
 1d6:	89 e5                	mov    %esp,%ebp
 1d8:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
 1db:	8b 45 10             	mov    0x10(%ebp),%eax
 1de:	89 44 24 08          	mov    %eax,0x8(%esp)
 1e2:	8b 45 0c             	mov    0xc(%ebp),%eax
 1e5:	89 44 24 04          	mov    %eax,0x4(%esp)
 1e9:	8b 45 08             	mov    0x8(%ebp),%eax
 1ec:	89 04 24             	mov    %eax,(%esp)
 1ef:	e8 20 ff ff ff       	call   114 <stosb>
  return dst;
 1f4:	8b 45 08             	mov    0x8(%ebp),%eax
}
 1f7:	c9                   	leave  
 1f8:	c3                   	ret    

000001f9 <strchr>:

char*
strchr(const char *s, char c)
{
 1f9:	55                   	push   %ebp
 1fa:	89 e5                	mov    %esp,%ebp
 1fc:	83 ec 04             	sub    $0x4,%esp
 1ff:	8b 45 0c             	mov    0xc(%ebp),%eax
 202:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
 205:	eb 14                	jmp    21b <strchr+0x22>
    if(*s == c)
 207:	8b 45 08             	mov    0x8(%ebp),%eax
 20a:	0f b6 00             	movzbl (%eax),%eax
 20d:	3a 45 fc             	cmp    -0x4(%ebp),%al
 210:	75 05                	jne    217 <strchr+0x1e>
      return (char*)s;
 212:	8b 45 08             	mov    0x8(%ebp),%eax
 215:	eb 13                	jmp    22a <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
 217:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 21b:	8b 45 08             	mov    0x8(%ebp),%eax
 21e:	0f b6 00             	movzbl (%eax),%eax
 221:	84 c0                	test   %al,%al
 223:	75 e2                	jne    207 <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
 225:	b8 00 00 00 00       	mov    $0x0,%eax
}
 22a:	c9                   	leave  
 22b:	c3                   	ret    

0000022c <gets>:

char*
gets(char *buf, int max)
{
 22c:	55                   	push   %ebp
 22d:	89 e5                	mov    %esp,%ebp
 22f:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 232:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 239:	eb 46                	jmp    281 <gets+0x55>
    cc = read(0, &c, 1);
 23b:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 242:	00 
 243:	8d 45 ef             	lea    -0x11(%ebp),%eax
 246:	89 44 24 04          	mov    %eax,0x4(%esp)
 24a:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 251:	e8 3e 01 00 00       	call   394 <read>
 256:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
 259:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 25d:	7e 2f                	jle    28e <gets+0x62>
      break;
    buf[i++] = c;
 25f:	8b 55 f4             	mov    -0xc(%ebp),%edx
 262:	8b 45 08             	mov    0x8(%ebp),%eax
 265:	01 c2                	add    %eax,%edx
 267:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 26b:	88 02                	mov    %al,(%edx)
 26d:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
 271:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 275:	3c 0a                	cmp    $0xa,%al
 277:	74 16                	je     28f <gets+0x63>
 279:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 27d:	3c 0d                	cmp    $0xd,%al
 27f:	74 0e                	je     28f <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 281:	8b 45 f4             	mov    -0xc(%ebp),%eax
 284:	83 c0 01             	add    $0x1,%eax
 287:	3b 45 0c             	cmp    0xc(%ebp),%eax
 28a:	7c af                	jl     23b <gets+0xf>
 28c:	eb 01                	jmp    28f <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
 28e:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
 28f:	8b 55 f4             	mov    -0xc(%ebp),%edx
 292:	8b 45 08             	mov    0x8(%ebp),%eax
 295:	01 d0                	add    %edx,%eax
 297:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
 29a:	8b 45 08             	mov    0x8(%ebp),%eax
}
 29d:	c9                   	leave  
 29e:	c3                   	ret    

0000029f <stat>:

int
stat(char *n, struct stat *st)
{
 29f:	55                   	push   %ebp
 2a0:	89 e5                	mov    %esp,%ebp
 2a2:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
 2a5:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
 2ac:	00 
 2ad:	8b 45 08             	mov    0x8(%ebp),%eax
 2b0:	89 04 24             	mov    %eax,(%esp)
 2b3:	e8 04 01 00 00       	call   3bc <open>
 2b8:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
 2bb:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 2bf:	79 07                	jns    2c8 <stat+0x29>
    return -1;
 2c1:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
 2c6:	eb 23                	jmp    2eb <stat+0x4c>
  r = fstat(fd, st);
 2c8:	8b 45 0c             	mov    0xc(%ebp),%eax
 2cb:	89 44 24 04          	mov    %eax,0x4(%esp)
 2cf:	8b 45 f4             	mov    -0xc(%ebp),%eax
 2d2:	89 04 24             	mov    %eax,(%esp)
 2d5:	e8 fa 00 00 00       	call   3d4 <fstat>
 2da:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
 2dd:	8b 45 f4             	mov    -0xc(%ebp),%eax
 2e0:	89 04 24             	mov    %eax,(%esp)
 2e3:	e8 bc 00 00 00       	call   3a4 <close>
  return r;
 2e8:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
 2eb:	c9                   	leave  
 2ec:	c3                   	ret    

000002ed <atoi>:

int
atoi(const char *s)
{
 2ed:	55                   	push   %ebp
 2ee:	89 e5                	mov    %esp,%ebp
 2f0:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
 2f3:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
 2fa:	eb 23                	jmp    31f <atoi+0x32>
    n = n*10 + *s++ - '0';
 2fc:	8b 55 fc             	mov    -0x4(%ebp),%edx
 2ff:	89 d0                	mov    %edx,%eax
 301:	c1 e0 02             	shl    $0x2,%eax
 304:	01 d0                	add    %edx,%eax
 306:	01 c0                	add    %eax,%eax
 308:	89 c2                	mov    %eax,%edx
 30a:	8b 45 08             	mov    0x8(%ebp),%eax
 30d:	0f b6 00             	movzbl (%eax),%eax
 310:	0f be c0             	movsbl %al,%eax
 313:	01 d0                	add    %edx,%eax
 315:	83 e8 30             	sub    $0x30,%eax
 318:	89 45 fc             	mov    %eax,-0x4(%ebp)
 31b:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
 31f:	8b 45 08             	mov    0x8(%ebp),%eax
 322:	0f b6 00             	movzbl (%eax),%eax
 325:	3c 2f                	cmp    $0x2f,%al
 327:	7e 0a                	jle    333 <atoi+0x46>
 329:	8b 45 08             	mov    0x8(%ebp),%eax
 32c:	0f b6 00             	movzbl (%eax),%eax
 32f:	3c 39                	cmp    $0x39,%al
 331:	7e c9                	jle    2fc <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
 333:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 336:	c9                   	leave  
 337:	c3                   	ret    

00000338 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
 338:	55                   	push   %ebp
 339:	89 e5                	mov    %esp,%ebp
 33b:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
 33e:	8b 45 08             	mov    0x8(%ebp),%eax
 341:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
 344:	8b 45 0c             	mov    0xc(%ebp),%eax
 347:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
 34a:	eb 13                	jmp    35f <memmove+0x27>
    *dst++ = *src++;
 34c:	8b 45 f8             	mov    -0x8(%ebp),%eax
 34f:	0f b6 10             	movzbl (%eax),%edx
 352:	8b 45 fc             	mov    -0x4(%ebp),%eax
 355:	88 10                	mov    %dl,(%eax)
 357:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 35b:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
 35f:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
 363:	0f 9f c0             	setg   %al
 366:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
 36a:	84 c0                	test   %al,%al
 36c:	75 de                	jne    34c <memmove+0x14>
    *dst++ = *src++;
  return vdst;
 36e:	8b 45 08             	mov    0x8(%ebp),%eax
}
 371:	c9                   	leave  
 372:	c3                   	ret    
 373:	90                   	nop

00000374 <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
 374:	b8 01 00 00 00       	mov    $0x1,%eax
 379:	cd 40                	int    $0x40
 37b:	c3                   	ret    

0000037c <exit>:
SYSCALL(exit)
 37c:	b8 02 00 00 00       	mov    $0x2,%eax
 381:	cd 40                	int    $0x40
 383:	c3                   	ret    

00000384 <wait>:
SYSCALL(wait)
 384:	b8 03 00 00 00       	mov    $0x3,%eax
 389:	cd 40                	int    $0x40
 38b:	c3                   	ret    

0000038c <pipe>:
SYSCALL(pipe)
 38c:	b8 04 00 00 00       	mov    $0x4,%eax
 391:	cd 40                	int    $0x40
 393:	c3                   	ret    

00000394 <read>:
SYSCALL(read)
 394:	b8 05 00 00 00       	mov    $0x5,%eax
 399:	cd 40                	int    $0x40
 39b:	c3                   	ret    

0000039c <write>:
SYSCALL(write)
 39c:	b8 10 00 00 00       	mov    $0x10,%eax
 3a1:	cd 40                	int    $0x40
 3a3:	c3                   	ret    

000003a4 <close>:
SYSCALL(close)
 3a4:	b8 15 00 00 00       	mov    $0x15,%eax
 3a9:	cd 40                	int    $0x40
 3ab:	c3                   	ret    

000003ac <kill>:
SYSCALL(kill)
 3ac:	b8 06 00 00 00       	mov    $0x6,%eax
 3b1:	cd 40                	int    $0x40
 3b3:	c3                   	ret    

000003b4 <exec>:
SYSCALL(exec)
 3b4:	b8 07 00 00 00       	mov    $0x7,%eax
 3b9:	cd 40                	int    $0x40
 3bb:	c3                   	ret    

000003bc <open>:
SYSCALL(open)
 3bc:	b8 0f 00 00 00       	mov    $0xf,%eax
 3c1:	cd 40                	int    $0x40
 3c3:	c3                   	ret    

000003c4 <mknod>:
SYSCALL(mknod)
 3c4:	b8 11 00 00 00       	mov    $0x11,%eax
 3c9:	cd 40                	int    $0x40
 3cb:	c3                   	ret    

000003cc <unlink>:
SYSCALL(unlink)
 3cc:	b8 12 00 00 00       	mov    $0x12,%eax
 3d1:	cd 40                	int    $0x40
 3d3:	c3                   	ret    

000003d4 <fstat>:
SYSCALL(fstat)
 3d4:	b8 08 00 00 00       	mov    $0x8,%eax
 3d9:	cd 40                	int    $0x40
 3db:	c3                   	ret    

000003dc <link>:
SYSCALL(link)
 3dc:	b8 13 00 00 00       	mov    $0x13,%eax
 3e1:	cd 40                	int    $0x40
 3e3:	c3                   	ret    

000003e4 <mkdir>:
SYSCALL(mkdir)
 3e4:	b8 14 00 00 00       	mov    $0x14,%eax
 3e9:	cd 40                	int    $0x40
 3eb:	c3                   	ret    

000003ec <chdir>:
SYSCALL(chdir)
 3ec:	b8 09 00 00 00       	mov    $0x9,%eax
 3f1:	cd 40                	int    $0x40
 3f3:	c3                   	ret    

000003f4 <dup>:
SYSCALL(dup)
 3f4:	b8 0a 00 00 00       	mov    $0xa,%eax
 3f9:	cd 40                	int    $0x40
 3fb:	c3                   	ret    

000003fc <getpid>:
SYSCALL(getpid)
 3fc:	b8 0b 00 00 00       	mov    $0xb,%eax
 401:	cd 40                	int    $0x40
 403:	c3                   	ret    

00000404 <sbrk>:
SYSCALL(sbrk)
 404:	b8 0c 00 00 00       	mov    $0xc,%eax
 409:	cd 40                	int    $0x40
 40b:	c3                   	ret    

0000040c <sleep>:
SYSCALL(sleep)
 40c:	b8 0d 00 00 00       	mov    $0xd,%eax
 411:	cd 40                	int    $0x40
 413:	c3                   	ret    

00000414 <uptime>:
SYSCALL(uptime)
 414:	b8 0e 00 00 00       	mov    $0xe,%eax
 419:	cd 40                	int    $0x40
 41b:	c3                   	ret    

0000041c <signal>:

//our addition
SYSCALL(signal)
 41c:	b8 1f 00 00 00       	mov    $0x1f,%eax
 421:	cd 40                	int    $0x40
 423:	c3                   	ret    

00000424 <sigsend>:
SYSCALL(sigsend)
 424:	b8 20 00 00 00       	mov    $0x20,%eax
 429:	cd 40                	int    $0x40
 42b:	c3                   	ret    

0000042c <alarm>:
SYSCALL(alarm)
 42c:	b8 21 00 00 00       	mov    $0x21,%eax
 431:	cd 40                	int    $0x40
 433:	c3                   	ret    

00000434 <getTicks>:
SYSCALL(getTicks)
 434:	b8 22 00 00 00       	mov    $0x22,%eax
 439:	cd 40                	int    $0x40
 43b:	c3                   	ret    

0000043c <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
 43c:	55                   	push   %ebp
 43d:	89 e5                	mov    %esp,%ebp
 43f:	83 ec 28             	sub    $0x28,%esp
 442:	8b 45 0c             	mov    0xc(%ebp),%eax
 445:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
 448:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 44f:	00 
 450:	8d 45 f4             	lea    -0xc(%ebp),%eax
 453:	89 44 24 04          	mov    %eax,0x4(%esp)
 457:	8b 45 08             	mov    0x8(%ebp),%eax
 45a:	89 04 24             	mov    %eax,(%esp)
 45d:	e8 3a ff ff ff       	call   39c <write>
}
 462:	c9                   	leave  
 463:	c3                   	ret    

00000464 <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
 464:	55                   	push   %ebp
 465:	89 e5                	mov    %esp,%ebp
 467:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
 46a:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
 471:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
 475:	74 17                	je     48e <printint+0x2a>
 477:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 47b:	79 11                	jns    48e <printint+0x2a>
    neg = 1;
 47d:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
 484:	8b 45 0c             	mov    0xc(%ebp),%eax
 487:	f7 d8                	neg    %eax
 489:	89 45 ec             	mov    %eax,-0x14(%ebp)
 48c:	eb 06                	jmp    494 <printint+0x30>
  } else {
    x = xx;
 48e:	8b 45 0c             	mov    0xc(%ebp),%eax
 491:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
 494:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
 49b:	8b 4d 10             	mov    0x10(%ebp),%ecx
 49e:	8b 45 ec             	mov    -0x14(%ebp),%eax
 4a1:	ba 00 00 00 00       	mov    $0x0,%edx
 4a6:	f7 f1                	div    %ecx
 4a8:	89 d0                	mov    %edx,%eax
 4aa:	0f b6 80 20 14 00 00 	movzbl 0x1420(%eax),%eax
 4b1:	8d 4d dc             	lea    -0x24(%ebp),%ecx
 4b4:	8b 55 f4             	mov    -0xc(%ebp),%edx
 4b7:	01 ca                	add    %ecx,%edx
 4b9:	88 02                	mov    %al,(%edx)
 4bb:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
 4bf:	8b 55 10             	mov    0x10(%ebp),%edx
 4c2:	89 55 d4             	mov    %edx,-0x2c(%ebp)
 4c5:	8b 45 ec             	mov    -0x14(%ebp),%eax
 4c8:	ba 00 00 00 00       	mov    $0x0,%edx
 4cd:	f7 75 d4             	divl   -0x2c(%ebp)
 4d0:	89 45 ec             	mov    %eax,-0x14(%ebp)
 4d3:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 4d7:	75 c2                	jne    49b <printint+0x37>
  if(neg)
 4d9:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 4dd:	74 2e                	je     50d <printint+0xa9>
    buf[i++] = '-';
 4df:	8d 55 dc             	lea    -0x24(%ebp),%edx
 4e2:	8b 45 f4             	mov    -0xc(%ebp),%eax
 4e5:	01 d0                	add    %edx,%eax
 4e7:	c6 00 2d             	movb   $0x2d,(%eax)
 4ea:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
 4ee:	eb 1d                	jmp    50d <printint+0xa9>
    putc(fd, buf[i]);
 4f0:	8d 55 dc             	lea    -0x24(%ebp),%edx
 4f3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 4f6:	01 d0                	add    %edx,%eax
 4f8:	0f b6 00             	movzbl (%eax),%eax
 4fb:	0f be c0             	movsbl %al,%eax
 4fe:	89 44 24 04          	mov    %eax,0x4(%esp)
 502:	8b 45 08             	mov    0x8(%ebp),%eax
 505:	89 04 24             	mov    %eax,(%esp)
 508:	e8 2f ff ff ff       	call   43c <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
 50d:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
 511:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 515:	79 d9                	jns    4f0 <printint+0x8c>
    putc(fd, buf[i]);
}
 517:	c9                   	leave  
 518:	c3                   	ret    

00000519 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
 519:	55                   	push   %ebp
 51a:	89 e5                	mov    %esp,%ebp
 51c:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
 51f:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
 526:	8d 45 0c             	lea    0xc(%ebp),%eax
 529:	83 c0 04             	add    $0x4,%eax
 52c:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
 52f:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
 536:	e9 7d 01 00 00       	jmp    6b8 <printf+0x19f>
    c = fmt[i] & 0xff;
 53b:	8b 55 0c             	mov    0xc(%ebp),%edx
 53e:	8b 45 f0             	mov    -0x10(%ebp),%eax
 541:	01 d0                	add    %edx,%eax
 543:	0f b6 00             	movzbl (%eax),%eax
 546:	0f be c0             	movsbl %al,%eax
 549:	25 ff 00 00 00       	and    $0xff,%eax
 54e:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
 551:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 555:	75 2c                	jne    583 <printf+0x6a>
      if(c == '%'){
 557:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 55b:	75 0c                	jne    569 <printf+0x50>
        state = '%';
 55d:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
 564:	e9 4b 01 00 00       	jmp    6b4 <printf+0x19b>
      } else {
        putc(fd, c);
 569:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 56c:	0f be c0             	movsbl %al,%eax
 56f:	89 44 24 04          	mov    %eax,0x4(%esp)
 573:	8b 45 08             	mov    0x8(%ebp),%eax
 576:	89 04 24             	mov    %eax,(%esp)
 579:	e8 be fe ff ff       	call   43c <putc>
 57e:	e9 31 01 00 00       	jmp    6b4 <printf+0x19b>
      }
    } else if(state == '%'){
 583:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
 587:	0f 85 27 01 00 00    	jne    6b4 <printf+0x19b>
      if(c == 'd'){
 58d:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
 591:	75 2d                	jne    5c0 <printf+0xa7>
        printint(fd, *ap, 10, 1);
 593:	8b 45 e8             	mov    -0x18(%ebp),%eax
 596:	8b 00                	mov    (%eax),%eax
 598:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
 59f:	00 
 5a0:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
 5a7:	00 
 5a8:	89 44 24 04          	mov    %eax,0x4(%esp)
 5ac:	8b 45 08             	mov    0x8(%ebp),%eax
 5af:	89 04 24             	mov    %eax,(%esp)
 5b2:	e8 ad fe ff ff       	call   464 <printint>
        ap++;
 5b7:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 5bb:	e9 ed 00 00 00       	jmp    6ad <printf+0x194>
      } else if(c == 'x' || c == 'p'){
 5c0:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
 5c4:	74 06                	je     5cc <printf+0xb3>
 5c6:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
 5ca:	75 2d                	jne    5f9 <printf+0xe0>
        printint(fd, *ap, 16, 0);
 5cc:	8b 45 e8             	mov    -0x18(%ebp),%eax
 5cf:	8b 00                	mov    (%eax),%eax
 5d1:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
 5d8:	00 
 5d9:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
 5e0:	00 
 5e1:	89 44 24 04          	mov    %eax,0x4(%esp)
 5e5:	8b 45 08             	mov    0x8(%ebp),%eax
 5e8:	89 04 24             	mov    %eax,(%esp)
 5eb:	e8 74 fe ff ff       	call   464 <printint>
        ap++;
 5f0:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 5f4:	e9 b4 00 00 00       	jmp    6ad <printf+0x194>
      } else if(c == 's'){
 5f9:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
 5fd:	75 46                	jne    645 <printf+0x12c>
        s = (char*)*ap;
 5ff:	8b 45 e8             	mov    -0x18(%ebp),%eax
 602:	8b 00                	mov    (%eax),%eax
 604:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
 607:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
 60b:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 60f:	75 27                	jne    638 <printf+0x11f>
          s = "(null)";
 611:	c7 45 f4 ba 0f 00 00 	movl   $0xfba,-0xc(%ebp)
        while(*s != 0){
 618:	eb 1e                	jmp    638 <printf+0x11f>
          putc(fd, *s);
 61a:	8b 45 f4             	mov    -0xc(%ebp),%eax
 61d:	0f b6 00             	movzbl (%eax),%eax
 620:	0f be c0             	movsbl %al,%eax
 623:	89 44 24 04          	mov    %eax,0x4(%esp)
 627:	8b 45 08             	mov    0x8(%ebp),%eax
 62a:	89 04 24             	mov    %eax,(%esp)
 62d:	e8 0a fe ff ff       	call   43c <putc>
          s++;
 632:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 636:	eb 01                	jmp    639 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
 638:	90                   	nop
 639:	8b 45 f4             	mov    -0xc(%ebp),%eax
 63c:	0f b6 00             	movzbl (%eax),%eax
 63f:	84 c0                	test   %al,%al
 641:	75 d7                	jne    61a <printf+0x101>
 643:	eb 68                	jmp    6ad <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
 645:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
 649:	75 1d                	jne    668 <printf+0x14f>
        putc(fd, *ap);
 64b:	8b 45 e8             	mov    -0x18(%ebp),%eax
 64e:	8b 00                	mov    (%eax),%eax
 650:	0f be c0             	movsbl %al,%eax
 653:	89 44 24 04          	mov    %eax,0x4(%esp)
 657:	8b 45 08             	mov    0x8(%ebp),%eax
 65a:	89 04 24             	mov    %eax,(%esp)
 65d:	e8 da fd ff ff       	call   43c <putc>
        ap++;
 662:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 666:	eb 45                	jmp    6ad <printf+0x194>
      } else if(c == '%'){
 668:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 66c:	75 17                	jne    685 <printf+0x16c>
        putc(fd, c);
 66e:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 671:	0f be c0             	movsbl %al,%eax
 674:	89 44 24 04          	mov    %eax,0x4(%esp)
 678:	8b 45 08             	mov    0x8(%ebp),%eax
 67b:	89 04 24             	mov    %eax,(%esp)
 67e:	e8 b9 fd ff ff       	call   43c <putc>
 683:	eb 28                	jmp    6ad <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
 685:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
 68c:	00 
 68d:	8b 45 08             	mov    0x8(%ebp),%eax
 690:	89 04 24             	mov    %eax,(%esp)
 693:	e8 a4 fd ff ff       	call   43c <putc>
        putc(fd, c);
 698:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 69b:	0f be c0             	movsbl %al,%eax
 69e:	89 44 24 04          	mov    %eax,0x4(%esp)
 6a2:	8b 45 08             	mov    0x8(%ebp),%eax
 6a5:	89 04 24             	mov    %eax,(%esp)
 6a8:	e8 8f fd ff ff       	call   43c <putc>
      }
      state = 0;
 6ad:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
 6b4:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
 6b8:	8b 55 0c             	mov    0xc(%ebp),%edx
 6bb:	8b 45 f0             	mov    -0x10(%ebp),%eax
 6be:	01 d0                	add    %edx,%eax
 6c0:	0f b6 00             	movzbl (%eax),%eax
 6c3:	84 c0                	test   %al,%al
 6c5:	0f 85 70 fe ff ff    	jne    53b <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
 6cb:	c9                   	leave  
 6cc:	c3                   	ret    
 6cd:	66 90                	xchg   %ax,%ax
 6cf:	90                   	nop

000006d0 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
 6d0:	55                   	push   %ebp
 6d1:	89 e5                	mov    %esp,%ebp
 6d3:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
 6d6:	8b 45 08             	mov    0x8(%ebp),%eax
 6d9:	83 e8 08             	sub    $0x8,%eax
 6dc:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 6df:	a1 48 14 00 00       	mov    0x1448,%eax
 6e4:	89 45 fc             	mov    %eax,-0x4(%ebp)
 6e7:	eb 24                	jmp    70d <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
 6e9:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6ec:	8b 00                	mov    (%eax),%eax
 6ee:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 6f1:	77 12                	ja     705 <free+0x35>
 6f3:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6f6:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 6f9:	77 24                	ja     71f <free+0x4f>
 6fb:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6fe:	8b 00                	mov    (%eax),%eax
 700:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 703:	77 1a                	ja     71f <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 705:	8b 45 fc             	mov    -0x4(%ebp),%eax
 708:	8b 00                	mov    (%eax),%eax
 70a:	89 45 fc             	mov    %eax,-0x4(%ebp)
 70d:	8b 45 f8             	mov    -0x8(%ebp),%eax
 710:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 713:	76 d4                	jbe    6e9 <free+0x19>
 715:	8b 45 fc             	mov    -0x4(%ebp),%eax
 718:	8b 00                	mov    (%eax),%eax
 71a:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 71d:	76 ca                	jbe    6e9 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
 71f:	8b 45 f8             	mov    -0x8(%ebp),%eax
 722:	8b 40 04             	mov    0x4(%eax),%eax
 725:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 72c:	8b 45 f8             	mov    -0x8(%ebp),%eax
 72f:	01 c2                	add    %eax,%edx
 731:	8b 45 fc             	mov    -0x4(%ebp),%eax
 734:	8b 00                	mov    (%eax),%eax
 736:	39 c2                	cmp    %eax,%edx
 738:	75 24                	jne    75e <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
 73a:	8b 45 f8             	mov    -0x8(%ebp),%eax
 73d:	8b 50 04             	mov    0x4(%eax),%edx
 740:	8b 45 fc             	mov    -0x4(%ebp),%eax
 743:	8b 00                	mov    (%eax),%eax
 745:	8b 40 04             	mov    0x4(%eax),%eax
 748:	01 c2                	add    %eax,%edx
 74a:	8b 45 f8             	mov    -0x8(%ebp),%eax
 74d:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
 750:	8b 45 fc             	mov    -0x4(%ebp),%eax
 753:	8b 00                	mov    (%eax),%eax
 755:	8b 10                	mov    (%eax),%edx
 757:	8b 45 f8             	mov    -0x8(%ebp),%eax
 75a:	89 10                	mov    %edx,(%eax)
 75c:	eb 0a                	jmp    768 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
 75e:	8b 45 fc             	mov    -0x4(%ebp),%eax
 761:	8b 10                	mov    (%eax),%edx
 763:	8b 45 f8             	mov    -0x8(%ebp),%eax
 766:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
 768:	8b 45 fc             	mov    -0x4(%ebp),%eax
 76b:	8b 40 04             	mov    0x4(%eax),%eax
 76e:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 775:	8b 45 fc             	mov    -0x4(%ebp),%eax
 778:	01 d0                	add    %edx,%eax
 77a:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 77d:	75 20                	jne    79f <free+0xcf>
    p->s.size += bp->s.size;
 77f:	8b 45 fc             	mov    -0x4(%ebp),%eax
 782:	8b 50 04             	mov    0x4(%eax),%edx
 785:	8b 45 f8             	mov    -0x8(%ebp),%eax
 788:	8b 40 04             	mov    0x4(%eax),%eax
 78b:	01 c2                	add    %eax,%edx
 78d:	8b 45 fc             	mov    -0x4(%ebp),%eax
 790:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
 793:	8b 45 f8             	mov    -0x8(%ebp),%eax
 796:	8b 10                	mov    (%eax),%edx
 798:	8b 45 fc             	mov    -0x4(%ebp),%eax
 79b:	89 10                	mov    %edx,(%eax)
 79d:	eb 08                	jmp    7a7 <free+0xd7>
  } else
    p->s.ptr = bp;
 79f:	8b 45 fc             	mov    -0x4(%ebp),%eax
 7a2:	8b 55 f8             	mov    -0x8(%ebp),%edx
 7a5:	89 10                	mov    %edx,(%eax)
  freep = p;
 7a7:	8b 45 fc             	mov    -0x4(%ebp),%eax
 7aa:	a3 48 14 00 00       	mov    %eax,0x1448
}
 7af:	c9                   	leave  
 7b0:	c3                   	ret    

000007b1 <morecore>:

static Header*
morecore(uint nu)
{
 7b1:	55                   	push   %ebp
 7b2:	89 e5                	mov    %esp,%ebp
 7b4:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
 7b7:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
 7be:	77 07                	ja     7c7 <morecore+0x16>
    nu = 4096;
 7c0:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
 7c7:	8b 45 08             	mov    0x8(%ebp),%eax
 7ca:	c1 e0 03             	shl    $0x3,%eax
 7cd:	89 04 24             	mov    %eax,(%esp)
 7d0:	e8 2f fc ff ff       	call   404 <sbrk>
 7d5:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
 7d8:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
 7dc:	75 07                	jne    7e5 <morecore+0x34>
    return 0;
 7de:	b8 00 00 00 00       	mov    $0x0,%eax
 7e3:	eb 22                	jmp    807 <morecore+0x56>
  hp = (Header*)p;
 7e5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7e8:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
 7eb:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7ee:	8b 55 08             	mov    0x8(%ebp),%edx
 7f1:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
 7f4:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7f7:	83 c0 08             	add    $0x8,%eax
 7fa:	89 04 24             	mov    %eax,(%esp)
 7fd:	e8 ce fe ff ff       	call   6d0 <free>
  return freep;
 802:	a1 48 14 00 00       	mov    0x1448,%eax
}
 807:	c9                   	leave  
 808:	c3                   	ret    

00000809 <malloc>:

void*
malloc(uint nbytes)
{
 809:	55                   	push   %ebp
 80a:	89 e5                	mov    %esp,%ebp
 80c:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
 80f:	8b 45 08             	mov    0x8(%ebp),%eax
 812:	83 c0 07             	add    $0x7,%eax
 815:	c1 e8 03             	shr    $0x3,%eax
 818:	83 c0 01             	add    $0x1,%eax
 81b:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
 81e:	a1 48 14 00 00       	mov    0x1448,%eax
 823:	89 45 f0             	mov    %eax,-0x10(%ebp)
 826:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 82a:	75 23                	jne    84f <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
 82c:	c7 45 f0 40 14 00 00 	movl   $0x1440,-0x10(%ebp)
 833:	8b 45 f0             	mov    -0x10(%ebp),%eax
 836:	a3 48 14 00 00       	mov    %eax,0x1448
 83b:	a1 48 14 00 00       	mov    0x1448,%eax
 840:	a3 40 14 00 00       	mov    %eax,0x1440
    base.s.size = 0;
 845:	c7 05 44 14 00 00 00 	movl   $0x0,0x1444
 84c:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 84f:	8b 45 f0             	mov    -0x10(%ebp),%eax
 852:	8b 00                	mov    (%eax),%eax
 854:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
 857:	8b 45 f4             	mov    -0xc(%ebp),%eax
 85a:	8b 40 04             	mov    0x4(%eax),%eax
 85d:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 860:	72 4d                	jb     8af <malloc+0xa6>
      if(p->s.size == nunits)
 862:	8b 45 f4             	mov    -0xc(%ebp),%eax
 865:	8b 40 04             	mov    0x4(%eax),%eax
 868:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 86b:	75 0c                	jne    879 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
 86d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 870:	8b 10                	mov    (%eax),%edx
 872:	8b 45 f0             	mov    -0x10(%ebp),%eax
 875:	89 10                	mov    %edx,(%eax)
 877:	eb 26                	jmp    89f <malloc+0x96>
      else {
        p->s.size -= nunits;
 879:	8b 45 f4             	mov    -0xc(%ebp),%eax
 87c:	8b 40 04             	mov    0x4(%eax),%eax
 87f:	89 c2                	mov    %eax,%edx
 881:	2b 55 ec             	sub    -0x14(%ebp),%edx
 884:	8b 45 f4             	mov    -0xc(%ebp),%eax
 887:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
 88a:	8b 45 f4             	mov    -0xc(%ebp),%eax
 88d:	8b 40 04             	mov    0x4(%eax),%eax
 890:	c1 e0 03             	shl    $0x3,%eax
 893:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
 896:	8b 45 f4             	mov    -0xc(%ebp),%eax
 899:	8b 55 ec             	mov    -0x14(%ebp),%edx
 89c:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
 89f:	8b 45 f0             	mov    -0x10(%ebp),%eax
 8a2:	a3 48 14 00 00       	mov    %eax,0x1448
      return (void*)(p + 1);
 8a7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8aa:	83 c0 08             	add    $0x8,%eax
 8ad:	eb 38                	jmp    8e7 <malloc+0xde>
    }
    if(p == freep)
 8af:	a1 48 14 00 00       	mov    0x1448,%eax
 8b4:	39 45 f4             	cmp    %eax,-0xc(%ebp)
 8b7:	75 1b                	jne    8d4 <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
 8b9:	8b 45 ec             	mov    -0x14(%ebp),%eax
 8bc:	89 04 24             	mov    %eax,(%esp)
 8bf:	e8 ed fe ff ff       	call   7b1 <morecore>
 8c4:	89 45 f4             	mov    %eax,-0xc(%ebp)
 8c7:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 8cb:	75 07                	jne    8d4 <malloc+0xcb>
        return 0;
 8cd:	b8 00 00 00 00       	mov    $0x0,%eax
 8d2:	eb 13                	jmp    8e7 <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 8d4:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8d7:	89 45 f0             	mov    %eax,-0x10(%ebp)
 8da:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8dd:	8b 00                	mov    (%eax),%eax
 8df:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
 8e2:	e9 70 ff ff ff       	jmp    857 <malloc+0x4e>
}
 8e7:	c9                   	leave  
 8e8:	c3                   	ret    
 8e9:	66 90                	xchg   %ax,%ax
 8eb:	90                   	nop

000008ec <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
 8ec:	55                   	push   %ebp
 8ed:	89 e5                	mov    %esp,%ebp
 8ef:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
 8f2:	c7 05 60 14 00 00 00 	movl   $0x0,0x1460
 8f9:	00 00 00 
	STORE_ESP(ttable[0].esp);
 8fc:	89 e0                	mov    %esp,%eax
 8fe:	a3 64 14 00 00       	mov    %eax,0x1464
	STORE_EBP(ttable[0].ebp);
 903:	89 e8                	mov    %ebp,%eax
 905:	a3 68 14 00 00       	mov    %eax,0x1468
	ttable[0].state = T_RUNNING;
 90a:	c7 05 70 14 00 00 01 	movl   $0x1,0x1470
 911:	00 00 00 
	ttable[0].wait_num = 0;
 914:	c7 05 74 15 00 00 00 	movl   $0x0,0x1574
 91b:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 91e:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 925:	eb 2c                	jmp    953 <uthread_init+0x67>
	{
		ttable[i].tid = i;
 927:	8b 45 f4             	mov    -0xc(%ebp),%eax
 92a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 930:	8d 90 60 14 00 00    	lea    0x1460(%eax),%edx
 936:	8b 45 f4             	mov    -0xc(%ebp),%eax
 939:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
 93b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 93e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 944:	05 70 14 00 00       	add    $0x1470,%eax
 949:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 94f:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 953:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 957:	7e ce                	jle    927 <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
 959:	c7 44 24 04 df 0b 00 	movl   $0xbdf,0x4(%esp)
 960:	00 
 961:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
 968:	e8 af fa ff ff       	call   41c <signal>
	alarm(THREAD_QUANTA);
 96d:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 974:	e8 b3 fa ff ff       	call   42c <alarm>
}
 979:	c9                   	leave  
 97a:	c3                   	ret    

0000097b <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
 97b:	55                   	push   %ebp
 97c:	89 e5                	mov    %esp,%ebp
 97e:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
 981:	60                   	pusha  
	ticks = getTicks();
 982:	e8 ad fa ff ff       	call   434 <getTicks>
 987:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
 98a:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 991:	e8 96 fa ff ff       	call   42c <alarm>
	asm("popa");
 996:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
 997:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 99e:	e9 02 01 00 00       	jmp    aa5 <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
 9a3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9a6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9ac:	05 70 14 00 00       	add    $0x1470,%eax
 9b1:	8b 00                	mov    (%eax),%eax
 9b3:	85 c0                	test   %eax,%eax
 9b5:	0f 85 e6 00 00 00    	jne    aa1 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
 9bb:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
 9c2:	e8 42 fe ff ff       	call   809 <malloc>
 9c7:	8b 55 f4             	mov    -0xc(%ebp),%edx
 9ca:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 9d0:	81 c2 60 14 00 00    	add    $0x1460,%edx
 9d6:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
 9d9:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9dc:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9e2:	05 60 14 00 00       	add    $0x1460,%eax
 9e7:	8b 40 0c             	mov    0xc(%eax),%eax
 9ea:	05 00 10 00 00       	add    $0x1000,%eax
 9ef:	89 c4                	mov    %eax,%esp
			PUSH(arg);
 9f1:	8b 45 0c             	mov    0xc(%ebp),%eax
 9f4:	89 c7                	mov    %eax,%edi
 9f6:	57                   	push   %edi
			PUSH(uthread_exit);
 9f7:	b8 65 0c 00 00       	mov    $0xc65,%eax
 9fc:	89 c7                	mov    %eax,%edi
 9fe:	57                   	push   %edi
			PUSH(start_func);
 9ff:	8b 45 08             	mov    0x8(%ebp),%eax
 a02:	89 c7                	mov    %eax,%edi
 a04:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
 a05:	b8 00 00 00 00       	mov    $0x0,%eax
 a0a:	89 c7                	mov    %eax,%edi
 a0c:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
 a0d:	89 e0                	mov    %esp,%eax
 a0f:	8b 55 f4             	mov    -0xc(%ebp),%edx
 a12:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 a18:	81 c2 60 14 00 00    	add    $0x1460,%edx
 a1e:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
 a21:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a24:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a2a:	05 60 14 00 00       	add    $0x1460,%eax
 a2f:	8b 40 08             	mov    0x8(%eax),%eax
 a32:	8b 55 f4             	mov    -0xc(%ebp),%edx
 a35:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 a3b:	81 c2 60 14 00 00    	add    $0x1460,%edx
 a41:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
 a44:	a1 4c 14 00 00       	mov    0x144c,%eax
 a49:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a4f:	05 60 14 00 00       	add    $0x1460,%eax
 a54:	8b 40 04             	mov    0x4(%eax),%eax
 a57:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
 a59:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a5c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a62:	05 70 14 00 00       	add    $0x1470,%eax
 a67:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
 a6d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a70:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a76:	05 70 15 00 00       	add    $0x1570,%eax
 a7b:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
 a82:	60                   	pusha  
			alarm(ticks);
 a83:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a86:	89 04 24             	mov    %eax,(%esp)
 a89:	e8 9e f9 ff ff       	call   42c <alarm>
			asm("popa");
 a8e:	61                   	popa   
			return ttable[i].tid;
 a8f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a92:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a98:	05 60 14 00 00       	add    $0x1460,%eax
 a9d:	8b 00                	mov    (%eax),%eax
 a9f:	eb 1e                	jmp    abf <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
 aa1:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 aa5:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 aa9:	0f 8e f4 fe ff ff    	jle    9a3 <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
 aaf:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ab2:	89 04 24             	mov    %eax,(%esp)
 ab5:	e8 72 f9 ff ff       	call   42c <alarm>
	//failed - no free thread to use
	return -1;
 aba:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 abf:	c9                   	leave  
 ac0:	c3                   	ret    

00000ac1 <safe_exit>:

// task 2.4


void safe_exit()
{
 ac1:	55                   	push   %ebp
 ac2:	89 e5                	mov    %esp,%ebp
 ac4:	83 ec 28             	sub    $0x28,%esp
 ac7:	eb 01                	jmp    aca <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
 ac9:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 aca:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 ad1:	eb 25                	jmp    af8 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
 ad3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 ad6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 adc:	05 70 14 00 00       	add    $0x1470,%eax
 ae1:	8b 00                	mov    (%eax),%eax
 ae3:	85 c0                	test   %eax,%eax
 ae5:	74 0d                	je     af4 <safe_exit+0x33>
				uthread_join(tid);
 ae7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 aea:	89 04 24             	mov    %eax,(%esp)
 aed:	e8 1d 02 00 00       	call   d0f <uthread_join>
				break;
 af2:	eb 0a                	jmp    afe <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 af4:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 af8:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 afc:	7e d5                	jle    ad3 <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
 afe:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
 b02:	75 c5                	jne    ac9 <safe_exit+0x8>
			exit();
 b04:	e8 73 f8 ff ff       	call   37c <exit>

00000b09 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
 b09:	55                   	push   %ebp
 b0a:	89 e5                	mov    %esp,%ebp
 b0c:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
 b0f:	a1 4c 14 00 00       	mov    0x144c,%eax
 b14:	8d 50 01             	lea    0x1(%eax),%edx
 b17:	89 d0                	mov    %edx,%eax
 b19:	c1 f8 1f             	sar    $0x1f,%eax
 b1c:	c1 e8 1a             	shr    $0x1a,%eax
 b1f:	01 c2                	add    %eax,%edx
 b21:	83 e2 3f             	and    $0x3f,%edx
 b24:	89 d1                	mov    %edx,%ecx
 b26:	29 c1                	sub    %eax,%ecx
 b28:	89 c8                	mov    %ecx,%eax
 b2a:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 b2d:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 b34:	eb 20                	jmp    b56 <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
 b36:	8b 45 f0             	mov    -0x10(%ebp),%eax
 b39:	8d 50 01             	lea    0x1(%eax),%edx
 b3c:	89 d0                	mov    %edx,%eax
 b3e:	c1 f8 1f             	sar    $0x1f,%eax
 b41:	c1 e8 1a             	shr    $0x1a,%eax
 b44:	01 c2                	add    %eax,%edx
 b46:	83 e2 3f             	and    $0x3f,%edx
 b49:	89 d1                	mov    %edx,%ecx
 b4b:	29 c1                	sub    %eax,%ecx
 b4d:	89 c8                	mov    %ecx,%eax
 b4f:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 b52:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 b56:	8b 45 f0             	mov    -0x10(%ebp),%eax
 b59:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b5f:	05 70 14 00 00       	add    $0x1470,%eax
 b64:	8b 00                	mov    (%eax),%eax
 b66:	83 f8 02             	cmp    $0x2,%eax
 b69:	74 06                	je     b71 <uthread_switch+0x68>
 b6b:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 b6f:	7e c5                	jle    b36 <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
 b71:	8b 15 4c 14 00 00    	mov    0x144c,%edx
 b77:	89 e0                	mov    %esp,%eax
 b79:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 b7f:	81 c2 60 14 00 00    	add    $0x1460,%edx
 b85:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
 b88:	8b 15 4c 14 00 00    	mov    0x144c,%edx
 b8e:	89 e8                	mov    %ebp,%eax
 b90:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 b96:	81 c2 60 14 00 00    	add    $0x1460,%edx
 b9c:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
 b9f:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ba2:	a3 4c 14 00 00       	mov    %eax,0x144c
	LOAD_EBP(ttable[c_thread].ebp);
 ba7:	a1 4c 14 00 00       	mov    0x144c,%eax
 bac:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bb2:	05 60 14 00 00       	add    $0x1460,%eax
 bb7:	8b 40 08             	mov    0x8(%eax),%eax
 bba:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
 bbc:	a1 4c 14 00 00       	mov    0x144c,%eax
 bc1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bc7:	05 60 14 00 00       	add    $0x1460,%eax
 bcc:	8b 40 04             	mov    0x4(%eax),%eax
 bcf:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
 bd1:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 bd8:	e8 4f f8 ff ff       	call   42c <alarm>
}
 bdd:	c9                   	leave  
 bde:	c3                   	ret    

00000bdf <uthread_yield>:

void uthread_yield()
{
 bdf:	55                   	push   %ebp
 be0:	89 e5                	mov    %esp,%ebp
 be2:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
 be5:	60                   	pusha  
	alarm(0);
 be6:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 bed:	e8 3a f8 ff ff       	call   42c <alarm>
	ttable[c_thread].state = T_RUNNABLE;
 bf2:	a1 4c 14 00 00       	mov    0x144c,%eax
 bf7:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bfd:	05 70 14 00 00       	add    $0x1470,%eax
 c02:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
 c08:	e8 fc fe ff ff       	call   b09 <uthread_switch>
	asm("popa");
 c0d:	61                   	popa   
}
 c0e:	c9                   	leave  
 c0f:	c3                   	ret    

00000c10 <uthread_awake>:

// task 2.5

void uthread_awake()
{
 c10:	55                   	push   %ebp
 c11:	89 e5                	mov    %esp,%ebp
 c13:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 c16:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 c1d:	eb 2c                	jmp    c4b <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
 c1f:	a1 4c 14 00 00       	mov    0x144c,%eax
 c24:	6b d0 46             	imul   $0x46,%eax,%edx
 c27:	8b 45 fc             	mov    -0x4(%ebp),%eax
 c2a:	01 d0                	add    %edx,%eax
 c2c:	83 c0 04             	add    $0x4,%eax
 c2f:	8b 04 85 64 14 00 00 	mov    0x1464(,%eax,4),%eax
 c36:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c3c:	05 70 14 00 00       	add    $0x1470,%eax
 c41:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 c47:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 c4b:	a1 4c 14 00 00       	mov    0x144c,%eax
 c50:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c56:	05 70 15 00 00       	add    $0x1570,%eax
 c5b:	8b 40 04             	mov    0x4(%eax),%eax
 c5e:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 c61:	7f bc                	jg     c1f <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
 c63:	c9                   	leave  
 c64:	c3                   	ret    

00000c65 <uthread_exit>:

void uthread_exit()
{
 c65:	55                   	push   %ebp
 c66:	89 e5                	mov    %esp,%ebp
 c68:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 c6b:	60                   	pusha  
	alarm(0);
 c6c:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c73:	e8 b4 f7 ff ff       	call   42c <alarm>
	asm("popa");
 c78:	61                   	popa   
	ttable[c_thread].state = T_FREE;
 c79:	a1 4c 14 00 00       	mov    0x144c,%eax
 c7e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c84:	05 70 14 00 00       	add    $0x1470,%eax
 c89:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
 c8f:	a1 4c 14 00 00       	mov    0x144c,%eax
 c94:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c9a:	05 60 14 00 00       	add    $0x1460,%eax
 c9f:	8b 00                	mov    (%eax),%eax
 ca1:	85 c0                	test   %eax,%eax
 ca3:	74 1d                	je     cc2 <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
 ca5:	a1 4c 14 00 00       	mov    0x144c,%eax
 caa:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cb0:	05 60 14 00 00       	add    $0x1460,%eax
 cb5:	8b 40 0c             	mov    0xc(%eax),%eax
 cb8:	89 04 24             	mov    %eax,(%esp)
 cbb:	e8 10 fa ff ff       	call   6d0 <free>
 cc0:	eb 05                	jmp    cc7 <uthread_exit+0x62>
	else
		safe_exit();
 cc2:	e8 fa fd ff ff       	call   ac1 <safe_exit>
	uthread_awake();
 cc7:	e8 44 ff ff ff       	call   c10 <uthread_awake>
	uthread_switch();
 ccc:	e8 38 fe ff ff       	call   b09 <uthread_switch>
	asm("popa");
 cd1:	61                   	popa   
}
 cd2:	c9                   	leave  
 cd3:	c3                   	ret    

00000cd4 <uthread_self>:

// task 2.6

int uthread_self()
{
 cd4:	55                   	push   %ebp
 cd5:	89 e5                	mov    %esp,%ebp
	return c_thread;
 cd7:	a1 4c 14 00 00       	mov    0x144c,%eax
}
 cdc:	5d                   	pop    %ebp
 cdd:	c3                   	ret    

00000cde <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
 cde:	55                   	push   %ebp
 cdf:	89 e5                	mov    %esp,%ebp
 ce1:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 ce4:	60                   	pusha  
	alarm(0);
 ce5:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 cec:	e8 3b f7 ff ff       	call   42c <alarm>
	ttable[c_thread].state = T_SLEEPING;
 cf1:	a1 4c 14 00 00       	mov    0x144c,%eax
 cf6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cfc:	05 70 14 00 00       	add    $0x1470,%eax
 d01:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
 d07:	e8 fd fd ff ff       	call   b09 <uthread_switch>
	asm("popa");
 d0c:	61                   	popa   
}
 d0d:	c9                   	leave  
 d0e:	c3                   	ret    

00000d0f <uthread_join>:

int uthread_join(int tid)
{
 d0f:	55                   	push   %ebp
 d10:	89 e5                	mov    %esp,%ebp
 d12:	53                   	push   %ebx
 d13:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
 d16:	60                   	pusha  
	ticks = getTicks();
 d17:	e8 18 f7 ff ff       	call   434 <getTicks>
 d1c:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 d1f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 d26:	e8 01 f7 ff ff       	call   42c <alarm>
	asm("popa");
 d2b:	61                   	popa   
	if (ttable[tid].state != T_FREE)
 d2c:	8b 45 08             	mov    0x8(%ebp),%eax
 d2f:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 d35:	05 70 14 00 00       	add    $0x1470,%eax
 d3a:	8b 00                	mov    (%eax),%eax
 d3c:	85 c0                	test   %eax,%eax
 d3e:	74 5e                	je     d9e <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
 d40:	8b 45 08             	mov    0x8(%ebp),%eax
 d43:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 d49:	05 10 01 00 00       	add    $0x110,%eax
 d4e:	05 60 14 00 00       	add    $0x1460,%eax
 d53:	8d 48 04             	lea    0x4(%eax),%ecx
 d56:	8b 45 08             	mov    0x8(%ebp),%eax
 d59:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 d5f:	05 70 15 00 00       	add    $0x1570,%eax
 d64:	8b 40 04             	mov    0x4(%eax),%eax
 d67:	8b 15 4c 14 00 00    	mov    0x144c,%edx
 d6d:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 d73:	81 c2 60 14 00 00    	add    $0x1460,%edx
 d79:	8b 12                	mov    (%edx),%edx
 d7b:	8b 5d 08             	mov    0x8(%ebp),%ebx
 d7e:	6b db 46             	imul   $0x46,%ebx,%ebx
 d81:	01 c3                	add    %eax,%ebx
 d83:	83 c3 04             	add    $0x4,%ebx
 d86:	89 14 9d 64 14 00 00 	mov    %edx,0x1464(,%ebx,4)
 d8d:	83 c0 01             	add    $0x1,%eax
 d90:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
 d92:	e8 47 ff ff ff       	call   cde <uthread_sleep>
		return 0;
 d97:	b8 00 00 00 00       	mov    $0x0,%eax
 d9c:	eb 12                	jmp    db0 <uthread_join+0xa1>
	}
	asm("pusha");
 d9e:	60                   	pusha  
	alarm(ticks);
 d9f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 da2:	89 04 24             	mov    %eax,(%esp)
 da5:	e8 82 f6 ff ff       	call   42c <alarm>
	asm("popa");
 daa:	61                   	popa   
	return -1;
 dab:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 db0:	83 c4 24             	add    $0x24,%esp
 db3:	5b                   	pop    %ebx
 db4:	5d                   	pop    %ebp
 db5:	c3                   	ret    

00000db6 <queue_init>:

void queue_init(struct tqueue *q)
{
 db6:	55                   	push   %ebp
 db7:	89 e5                	mov    %esp,%ebp
	q->head = 0;
 db9:	8b 45 08             	mov    0x8(%ebp),%eax
 dbc:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
 dc3:	00 00 00 
	q->tail = 0;
 dc6:	8b 45 08             	mov    0x8(%ebp),%eax
 dc9:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
 dd0:	00 00 00 
}
 dd3:	5d                   	pop    %ebp
 dd4:	c3                   	ret    

00000dd5 <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
 dd5:	55                   	push   %ebp
 dd6:	89 e5                	mov    %esp,%ebp
 dd8:	57                   	push   %edi
 dd9:	56                   	push   %esi
 dda:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
 ddb:	8b 45 08             	mov    0x8(%ebp),%eax
 dde:	8b 00                	mov    (%eax),%eax
 de0:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
 de6:	8b 45 08             	mov    0x8(%ebp),%eax
 de9:	8b 00                	mov    (%eax),%eax
 deb:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
 df1:	39 c2                	cmp    %eax,%edx
 df3:	75 07                	jne    dfc <dequeue+0x27>
		return 0;
 df5:	b9 00 00 00 00       	mov    $0x0,%ecx
 dfa:	eb 31                	jmp    e2d <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
 dfc:	8b 45 08             	mov    0x8(%ebp),%eax
 dff:	8b 18                	mov    (%eax),%ebx
 e01:	8b 45 08             	mov    0x8(%ebp),%eax
 e04:	8b 10                	mov    (%eax),%edx
 e06:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
 e0c:	89 c1                	mov    %eax,%ecx
 e0e:	c1 f9 1f             	sar    $0x1f,%ecx
 e11:	c1 e9 1a             	shr    $0x1a,%ecx
 e14:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 e17:	83 e6 3f             	and    $0x3f,%esi
 e1a:	89 f7                	mov    %esi,%edi
 e1c:	29 cf                	sub    %ecx,%edi
 e1e:	89 f9                	mov    %edi,%ecx
 e20:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
 e23:	83 c0 01             	add    $0x1,%eax
 e26:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
 e2c:	90                   	nop
 e2d:	89 c8                	mov    %ecx,%eax
}
 e2f:	5b                   	pop    %ebx
 e30:	5e                   	pop    %esi
 e31:	5f                   	pop    %edi
 e32:	5d                   	pop    %ebp
 e33:	c3                   	ret    

00000e34 <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
 e34:	55                   	push   %ebp
 e35:	89 e5                	mov    %esp,%ebp
 e37:	57                   	push   %edi
 e38:	56                   	push   %esi
 e39:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
 e3a:	8b 45 08             	mov    0x8(%ebp),%eax
 e3d:	8b 18                	mov    (%eax),%ebx
 e3f:	8b 45 08             	mov    0x8(%ebp),%eax
 e42:	8b 10                	mov    (%eax),%edx
 e44:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
 e4a:	89 c1                	mov    %eax,%ecx
 e4c:	c1 f9 1f             	sar    $0x1f,%ecx
 e4f:	c1 e9 1a             	shr    $0x1a,%ecx
 e52:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 e55:	83 e6 3f             	and    $0x3f,%esi
 e58:	89 f7                	mov    %esi,%edi
 e5a:	29 cf                	sub    %ecx,%edi
 e5c:	89 f9                	mov    %edi,%ecx
 e5e:	8b 35 4c 14 00 00    	mov    0x144c,%esi
 e64:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
 e6a:	81 c6 60 14 00 00    	add    $0x1460,%esi
 e70:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
 e73:	83 c0 01             	add    $0x1,%eax
 e76:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
 e7c:	5b                   	pop    %ebx
 e7d:	5e                   	pop    %esi
 e7e:	5f                   	pop    %edi
 e7f:	5d                   	pop    %ebp
 e80:	c3                   	ret    

00000e81 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
 e81:	55                   	push   %ebp
 e82:	89 e5                	mov    %esp,%ebp
 e84:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
 e87:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
 e8e:	e8 76 f9 ff ff       	call   809 <malloc>
 e93:	8b 55 08             	mov    0x8(%ebp),%edx
 e96:	89 02                	mov    %eax,(%edx)
	if (!value)
 e98:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 e9c:	75 0c                	jne    eaa <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
 e9e:	8b 45 08             	mov    0x8(%ebp),%eax
 ea1:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
 ea8:	eb 0a                	jmp    eb4 <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
 eaa:	8b 45 08             	mov    0x8(%ebp),%eax
 ead:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
 eb4:	c9                   	leave  
 eb5:	c3                   	ret    

00000eb6 <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
 eb6:	55                   	push   %ebp
 eb7:	89 e5                	mov    %esp,%ebp
 eb9:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
 ebc:	60                   	pusha  
	ticks = getTicks();
 ebd:	e8 72 f5 ff ff       	call   434 <getTicks>
 ec2:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 ec5:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 ecc:	e8 5b f5 ff ff       	call   42c <alarm>
	asm("popa");
 ed1:	61                   	popa   
	if (semaphore->state == S_LOCKED)
 ed2:	8b 45 08             	mov    0x8(%ebp),%eax
 ed5:	8b 40 04             	mov    0x4(%eax),%eax
 ed8:	83 f8 01             	cmp    $0x1,%eax
 edb:	75 1c                	jne    ef9 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
 edd:	8b 45 08             	mov    0x8(%ebp),%eax
 ee0:	89 04 24             	mov    %eax,(%esp)
 ee3:	e8 4c ff ff ff       	call   e34 <enqueue>
		uthread_sleep();
 ee8:	e8 f1 fd ff ff       	call   cde <uthread_sleep>
		alarm(0);
 eed:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 ef4:	e8 33 f5 ff ff       	call   42c <alarm>
	}
	semaphore->state = S_LOCKED;
 ef9:	8b 45 08             	mov    0x8(%ebp),%eax
 efc:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
 f03:	8b 45 f4             	mov    -0xc(%ebp),%eax
 f06:	89 04 24             	mov    %eax,(%esp)
 f09:	e8 1e f5 ff ff       	call   42c <alarm>

}
 f0e:	c9                   	leave  
 f0f:	c3                   	ret    

00000f10 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
 f10:	55                   	push   %ebp
 f11:	89 e5                	mov    %esp,%ebp
 f13:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
 f16:	60                   	pusha  
	ticks = getTicks();
 f17:	e8 18 f5 ff ff       	call   434 <getTicks>
 f1c:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 f1f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 f26:	e8 01 f5 ff ff       	call   42c <alarm>
	asm("popa");
 f2b:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
 f2c:	8b 45 08             	mov    0x8(%ebp),%eax
 f2f:	89 04 24             	mov    %eax,(%esp)
 f32:	e8 9e fe ff ff       	call   dd5 <dequeue>
 f37:	89 45 f0             	mov    %eax,-0x10(%ebp)
 f3a:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 f3e:	75 19                	jne    f59 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
 f40:	8b 45 08             	mov    0x8(%ebp),%eax
 f43:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
 f4a:	60                   	pusha  
		alarm(ticks);
 f4b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 f4e:	89 04 24             	mov    %eax,(%esp)
 f51:	e8 d6 f4 ff ff       	call   42c <alarm>
		asm("popa");
 f56:	61                   	popa   
 f57:	eb 0f                	jmp    f68 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
 f59:	8b 45 f0             	mov    -0x10(%ebp),%eax
 f5c:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
 f63:	e8 77 fc ff ff       	call   bdf <uthread_yield>
	}
}
 f68:	c9                   	leave  
 f69:	c3                   	ret    
